<?php
namespace Admin\Controller;
use Think\Controller;
class CatalogController extends Controller {
	public function __construct(){
		parent::__construct();
		if(!$_SESSION['admin_is_login']){
			$this->redirect('admin/Auth/login');
		}
	}
    public function index(){
    	$level1=M('product_catalog')->where('parent_id=0')->select();
    	$this->assign('level1',$level1);
    	$this->display();
    }
     public function del($id){
    	M('product_catalog')->where('id='.$id)->delete();
    	$this->redirect('admin/Catalog/index');	
    }
    public function add(){
        $level1=M('product_catalog')->where('parent_id=0')->select();
        $this->assign('level1',$level1);
        $this->display();
    }
    public function do_add(){
        M('product_catalog')->add(array(
            'name'=>I('post.name'),
            'parent_id'=>I('post.parent_id')
            
        ));
        $this->success('添加分类成功',U('admin/Catalog/index'));
    }
    public function edit($id){
        $catalog=M('product_catalog')->where('id='.$id)->find();
        $level1=M('product_catalog')->where('parent_id=0')->select();
        $this->assign('catalog',$catalog);
        $this->assign('level1',$level1);
        $this->display();
    }
    public function do_eidt(){
        $id=I('post.id');
        M('product_catalog')->where('id='.$id)->save(array(
            'name'=>I('post.name'),
            'parent_id'=>I('post.parent_id')
        ));
        $this->success('编辑分类成功',U('admin/Catalog/index'));
    }
}